//查询
$(document).on('click', '.sub-btn-seach', function () {
    var coin = $('#coin_name').val();
    var mobile = $('#user_mobile').val();
    var cmid = $('#user_cmid').val();
    if (!mobile && !cmid) {
        toasterror("请填写条件");
        return false;
    }
    $.ajax({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        url: '/assets/overView',
        data: {coin_name: coin, mobile: mobile, cmid: cmid},
        type: 'POST',
        error: function (e) {
            if (e.readyState === 4 && e.status === 422) {
                for (var i in e.responseJSON) {
                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                        err = e.responseJSON[i];
                        for (var j in err) {
                            toasterror(err[j][0]);
                        }
                    }
                }
            }
        },
        success: function (data) {
            if(data.success == 1){
                //官方奖励
                activityList(data.activityList);
                //冲币记录
                rechargeInList(data.rechargeInList);
                //提币记录
                rechargeOutList(data.rechargeOutList);
                //私人红包收入
                redPackInList(data.redPackInList);
                //私人红包支出
                redPackOutList(data.redPackOutList);
                //转账收入
                transInList(data.transInList);
                //转账支出
                transOutList(data.transOutList);
                //群红包收入
                groupRedPackInList(data.groupRedPackInList);
                //群红包支出
                groupRedPackOutList(data.groupRedPackOutList);
                toastsuccess(data.message);
            }else{
                toasterror(data.message);
            }


        }
    })
});
//转账收入
function transInList(data){
    $('.transInList').html("");
    if(data.length > 0 ){
        var arr = '<tr  class="even"><td>&nbsp;</td></tr><tr class="even"><td>来源类型</td><td>来源用户CMID</td><td>来源用户昵称</td><td>来源用户手机</td><td>来源用户状态</td><td>交易额</td><td>交易时间</td></tr>';
        $.each(data, function (name, value) {
            var status = '<span style="color:green;" class="sendUser" >正常</span>';
            if (value.status == 2) {
                status = "冻结";
            }
            arr = arr + '<tr  class="even"><td>转账</td><td>' + value.cmid + '</td> <td>' + value.name + '</td><td>' + value.mobile + '</td><td>' + status + '</td><td>' + value.number + '</td><td>' + value.created_at + '</td></tr>';
        });
        $('.transInList').append(arr);
    }
}
//转账支出
function transOutList(data){
    $('.transOutList').html("");
    if(data.length > 0 ){
        var arr = '<tr  class="even"><td>&nbsp;</td></tr><tr class="even"><td>支出类型</td><td>支出用户CMID</td><td>支出用户昵称</td><td>支出用户手机</td><td>支出用户状态</td><td>交易额</td><td>交易时间</td></tr>';
        $.each(data, function (name, value) {
            var status = '<span style="color:green;" class="sendUser" >正常</span>';
            if (value.status == 2) {
                status = "冻结";
            }
            arr = arr + '<tr  class="even"><td>转账</td><td>' + value.cmid + '</td> <td>' + value.name + '</td><td>' + value.mobile + '</td><td>' + status + '</td><td>' + value.number + '</td><td>' + value.created_at + '</td></tr>';
        });
        $('.transOutList').append(arr);
    }
}
//群红包收入
function groupRedPackInList(data){
    $('.groupRedPackInList').html("");
    if(data.length >0){
        var arr = '<tr class="even"><td>&nbsp;</td></tr><tr class="even"><td>编号</td><td>来源用户CMID</td><td>来源用户昵称</td><td>状态</td><td>交易额</td><td>交易时间</td></tr>';
        $.each(data, function (name, value) {
            var status = '<span style="color:green;" class="sendUser" >正常</span>';
            if (value.from_user_status == 2) {
                status = "冻结";
            }
            arr = arr + '<tr  class="even"><td>' + value.red_id + '</td> <td>' + value.from_user_cmid + '</td><td>' + value.from_user_name + '</td><td>' + status + '</td><td>' + value.number + '</td><td>' + value.created_at + '</td></tr>';
        });
        $('.groupRedPackInList').append(arr);
    }
}
//群红包支出
function groupRedPackOutList(data){
    $('.groupRedPackOutList').html("");
    if(data.length >0){
        var arr = '<tr class="even"><td>&nbsp;</td></tr><tr class="even"><td>编号</td><td>群CMID</td><td>群名称</td><td>金额</td><td>个数</td><td>时间</td></tr>';
        $.each(data, function (name, value) {
            arr = arr + '<tr  class="even"><td>' + value.id + '</td> <td>' + value.group_cmid + '</td><td>' + value.group_name + '</td><td>' + value.number + '</td><td>' + value.num + '</td><td>' + value.created_at + '</td></tr>';
        });
        $('.groupRedPackOutList').append(arr);
    }
}
//私人红包收入
function redPackInList(data){
    $('.redPackInList').html("");
    if(data.length > 0){
        var arr = '<tr  class="even"><td>&nbsp;</td></tr><tr class="even"><td>来源类型</td><td>来源用户CMID</td><td>来源用户昵称</td><td>来源用户手机</td><td>来源用户状态</td><td>交易额</td><td>交易时间</td></tr>';
        $.each(data, function (name, value) {
            var status = '<span style="color:green;" class="sendUser" >正常</span>';
            if (value.status == 2) {
                status = "冻结";
            }
            arr = arr + '<tr  class="even"><td>私人红包</td><td>' + value.cmid + '</td> <td>' + value.name + '</td><td>' + value.mobile + '</td><td>' + status + '</td><td>' + value.number + '</td><td>' + value.created_at + '</td></tr>';
        });
        $('.redPackInList').append(arr);
    }
}

//私人红包支出
function redPackOutList(data){
    $('.redPackOutList').html("");
    if(data.length > 0){
        var arr = '<tr  class="even"><td>&nbsp;</td></tr><tr class="even"><td>支出类型</td><td>支出用户CMID</td><td>支出用户昵称</td><td>支出用户手机</td><td>支出用户状态</td><td>交易额</td><td>交易时间</td></tr>';
        $.each(data, function (name, value) {
            var status = '<span style="color:green;" class="sendUser" >正常</span>';
            if (value.status == 2) {
                status = "冻结";
            }
            arr = arr + '<tr  class="even"><td>私人红包</td><td>' + value.cmid + '</td> <td>' + value.name + '</td><td>' + value.mobile + '</td><td>' + status + '</td><td>' + value.number + '</td><td>' + value.created_at + '</td></tr>';
        });
        $('.redPackOutList').append(arr);
    }
}

//冲币记录
function rechargeInList(data) {
    $('.rechargeList').html("");
    if(data.length > 0){
        var arr = '<tr class="even"><td>&nbsp;</td></tr><tr class="even"><td>交易号</td><td>数量</td><td>交易确认数</td><td>实际到账</td><td>状态</td><td>发起时间</td><td>变更时间</td><td>描述</td></tr>';
        $.each(data, function (name, value) {
            arr = arr + '<tr  class="even"><td style="cursor:pointer;" class="txid_hide " data-hide="1" data-txid="'+value.txid+'" data-txid_hide="'+value.txid_hide+'">' + value.txid_hide + '</td><td>' + value.number + '</td><td>' + value.confirmations + '</td><td>' + value.number_u + '</td><td>' + value.status + '</td><td>' + value.created_at + '</td><td>' + value.updated_at + '</td><td>' + value.description + '</td></tr>';
        });
        $('.rechargeList').append(arr);

    }
}
//提币记录
function rechargeOutList(data){
    $('.cashList').html("");
    if(data.length > 0){
        var arr = '<tr class="even"><td>&nbsp;</td></tr><tr class="even"><td>交易号</td><td>数量</td><td>交易确认数</td><td>实际到账</td><td>状态</td><td>发起时间</td><td>变更时间</td><td>描述</td></tr>';
        $.each(data, function (name, value) {
            arr = arr + '<tr  class="even"><td style="cursor:pointer;" class="txid_hide " data-hide="1" data-txid="'+value.txid+'"  data-txid_hide="'+value.txid_hide+'">' + value.txid_hide + '</td><td>' + value.number + '</td><td>' + value.confirmations + '</td><td>' + value.number_u + '</td><td>' + value.status + '</td><td>' + value.created_at + '</td><td>' + value.updated_at + '</td><td>' + value.description + '</td></tr>';
        });
        $('.cashList').append(arr);
    }
}

//活动奖励
function activityList(data){
    $('.activityList').html("");
    if(data.length > 0){
        var arr = '<tr class="even"><td>&nbsp;</td></tr><tr class="even"><td>编号</td><td>活动类型</td><td>状态</td><td>奖励金额</td><td>奖励时间</td></tr>';
        $.each(data, function (name, value) {
            arr = arr + '<tr  class="even"><td>' + value.id + '</td> <td>' + value.subtype + '</td><td>' + value.opt_type + '</td><td>' + value.number + '</td><td>' + value.created_at + '</td></tr>';
        });
        $('.activityList').append(arr);
    }
}

//显示和隐藏交易号
$(document).on('click', '.txid_hide', function () {
    var _this = $(this);
    var txid = _this.data('txid');
    var hide = _this.data('hide');
    var txid_hide = _this.data('txid_hide');
    if (hide == 1) {
        _this.html("["+txid+"]");
        _this.data('hide',2);
    }else{
        _this.html(txid_hide);
        _this.data('hide',1);
    }
});


//显示和隐藏分类
$(document).on('click', '.show-hide', function () {
    var _class = $(this).data('tip');
    console.log(_class);
    if ($('.' + _class).is(':hidden')) {
        $('.' + _class).show();
    } else {
        $('.' + _class).hide();
    }
});



